package com.hirosci.digitalscore;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;



public class BTConnection extends Connection {

	private final BluetoothAdapter mAdapter;
	private BluetoothSocket mSocket;
	Boolean connet;

	private static final UUID MY_UUID_INSECURE = UUID
			.fromString("00001101-0000-1000-8000-00805F9B34FB");
	
	public BTConnection(String address) {
		mAdapter = BluetoothAdapter.getDefaultAdapter();
		BluetoothDevice device = mAdapter.getRemoteDevice(address);
		try {
			mSocket = device
					.createInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);
			mSocket.connect();
			connet = true;
		} catch (IOException e) {
			connet = false;
		}
	}

	@Override
	public InputStream getInputStream() throws IOException {
		return mSocket.getInputStream();
	}

	@Override
	public OutputStream getOutputStream() throws IOException {
		return mSocket.getOutputStream();
	}

	@Override
	public void close() throws IOException {
		mSocket.close();
	}

	@Override
	public Boolean connetion() {
		// TODO Auto-generated method stub
		return connet;
	}

	 
	
}
